import eventSettings from "../utils/eventSettings";
import { location } from "../utils/getLocation";
import { getcmdfromchat, randomString } from "../utils/utils";

export function loadGreatSpook() {}

//万圣节活动内容
let PublicSpeakingDemonCooldown = 0;
register("chat", (message,event) => {
    if(!eventSettings.SkyblockGreatSpook || !location.inSkyblock) return;
    switch (true) {
        case (message.startsWith("Click HERE to sign ")):  //自动点击 "这里"
            const cmd = getcmdfromchat(event,"HERE");
            if(!cmd || !cmd.startsWith("/spookysignpaper")) return;
            if(eventSettings.SkyblockGreatSpookDelay) setTimeout(() => { ChatLib.say(cmd); }, Math.floor(500 + Math.random() * 500));
                else ChatLib.say(cmd);
            break;
        case (message.startsWith("QUICK MATHS! Solve: ")):  //自动做数学题
            const str = message.replace("QUICK MATHS! Solve: ","").replace(/x/ig,"*").replace(/[a-zA-Z]/ig,"");
            const num = eval(str);
            if(!num || isNaN(num)) return;
            if(eventSettings.SkyblockGreatSpookDelay) setTimeout(() => { ChatLib.command("ac " + num); }, Math.floor(500 + Math.random() * 500));
                else ChatLib.command("ac " + num);
            break;
        case (message.startsWith("[FEAR] Public Speaking Demon: Speak ")):  //自动说些什么
        case (message.startsWith("[FEAR] Public Speaking Demon: Say something interesting ")):
            if(Date.now() < PublicSpeakingDemonCooldown + 20 * 1000) return;
            const sayStr = Date.now() > PublicSpeakingDemonCooldown + 60 * 1000 ? (eventSettings.PublicSpeakingDemon ? eventSettings.PublicSpeakingDemon : message) : randomString(Math.floor(Math.random() * 16) + 16);
            PublicSpeakingDemonCooldown = Date.now();
            if(eventSettings.SkyblockGreatSpookDelay) setTimeout(() => { ChatLib.command("ac " + sayStr) }, Math.floor(500 + Math.random() * 500));
                else ChatLib.command("ac " + sayStr);
            break;
    }
}).setCriteria("${message}")